/*
 * uart_svc.h
 *
 *  Created on: Jul 17, 2020
 *      Author: liwei
 */

#ifndef EXAMPLES_WG_WG_MAIN_UART_SVC_H_
#define EXAMPLES_WG_WG_MAIN_UART_SVC_H_

#include "driver/gpio.h"
#include "driver/uart.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "ingwaycomm.h"

#define CONFIG_UART_TX1_GPIO (GPIO_NUM_17)
#define CONFIG_UART_RX1_GPIO (GPIO_NUM_35)
#define CONFIG_UART_CT1_GPIO (GPIO_NUM_4)

#define CONFIG_UART_TX2_GPIO (0)
#define CONFIG_UART_RX2_GPIO (0)
#define CONFIG_UART_CT2_GPIO (0)
#define CONFIG_UART_RX_BUFFSIZE 512 // 256
#define SELF_UART_BUFFER_SIZE 120 // refer to uart.c of "#define UART_FULL_THRESH_DEFAULT        (120)" in SDK.

extern QueueHandle_t mUart1_Queue;

typedef enum {
    COMM_PORT_COM1 = 1,
    COMM_PORT_COM2 = 2,
} CommPortTPDF;

typedef struct
{
    uint16_t usCommPort;
    uint16_t usBaudrateH;
    uint16_t usBaudrateL;
    uint16_t usWordSize;
    uint16_t usParity;
    uint16_t usStopBits;
} UartConfigTPDF;

extern void URT1_vInit(UartConfigTPDF* tCfg);
extern uint8_t URT1_dRx(char* ucData, uint16_t* usLen);
extern int URT1_dData_Send(char* cData, uint16_t usLen);

extern void URT2_vInit(UartConfigTPDF* tCfg);
extern uint8_t URT2_dRx(char* ucData, uint16_t* usLen);
extern int URT2_dData_Send(char* cData, uint16_t usLen);

#endif /* EXAMPLES_WG_WG_MAIN_UART_SVC_H_ */
